package
{
	import com.pickgliss.display.StageReferance;
	import com.pickgliss.events.AlertEvent;
	import com.pickgliss.ui.AlertManager;
	import com.pickgliss.ui.ComponentFactory;
	import com.pickgliss.ui.TipManager;
	import com.pickgliss.ui.controls.BaseButton;
	import com.pickgliss.ui.controls.ComboBox;
	import com.pickgliss.ui.controls.Frame;
	import com.pickgliss.ui.controls.IconButton;
	import com.pickgliss.ui.controls.ScrollPanel;
	import com.pickgliss.ui.controls.SelectedButtonGroup;
	import com.pickgliss.ui.controls.SelectedTextButton;
	import com.pickgliss.ui.controls.TextButton;
	import com.pickgliss.ui.controls.TextInput;
	import com.pickgliss.ui.controls.alert.BaseAlerFrame;
	import com.pickgliss.ui.controls.alert.SimpleAlert;
	import com.pickgliss.ui.controls.container.HBox;
	import com.pickgliss.ui.controls.container.VBox;
	import com.pickgliss.ui.controls.list.ListPanel;
	import com.pickgliss.ui.controls.list.ListTextButtonAdapter;
	import com.pickgliss.ui.controls.scroll.BaseScrollbar;
	import com.pickgliss.ui.controls.scroll.HScrollbar;
	import com.pickgliss.ui.controls.scroll.VScrollbar;
	import com.pickgliss.ui.controls.silder.HSilder;
	import com.pickgliss.ui.controls.silder.VSilder;
	import com.pickgliss.ui.image.CloneImage;
	import com.pickgliss.ui.image.MovieImage;
	import com.pickgliss.ui.image.MutipleImage;
	import com.pickgliss.ui.image.ScaleBitmapImage;
	import com.pickgliss.ui.image.ScaleFrameImage;
	import com.pickgliss.ui.text.BitmapText;
	import com.pickgliss.ui.text.FilterFrameText;
	import com.pickgliss.ui.text.GradientText;
	import com.pickgliss.ui.text.Text;
	import com.pickgliss.ui.tip.SimpleTip;
	import com.pickgliss.ui.vo.AlertInfo;
	import com.pickgliss.utils.ClassUtils;
	import com.pickgliss.utils.Directions;
	import com.pickgliss.utils.ObjectUtils;
	
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	[SWF(width='1000',height='600',frameRate='25')]
	public class RoadComponentTest extends MovieClip
	{
		public function RoadComponentTest()
		{
			if(stage)
			{
				init();
			}else
			{
				addEventListener(Event.ADDED_TO_STAGE,init);
			}
		}

		private function __onComponentinit(event:Event):void
		{
			removeEventListener(Event.ENTER_FRAME,__loadingTextHandler);
			new ScaleFrameImage();
			new MovieImage();
			new BaseButton();
			new FilterFrameText();
			new MutipleImage();
			new ScaleBitmapImage();
			new VScrollbar();
			new HScrollbar();
			new TextButton();
			new IconButton();
			new SimpleTip();
			new DropShadowFilter(4,45,0,1,5,5,0.5);
			new SimpleAlert();
			new CloneImage();
			
			var frame:Frame = ComponentFactory.Instance.creat("SimpleFrame");
			frame.x = 150;
			frame.y = 100;
			frame.width = 700;
			frame.height = 400;
			frame.titleText = "Pickgliss UIComponent";
			addChild(frame);
			
			var frameContent:Sprite = new Sprite();
			frame.addToContent(frameContent);
			
			var contentBackgound:ScaleBitmapImage = ComponentFactory.Instance.creat("PanelContentBackgoundAsset");
			contentBackgound.width = 660;
			contentBackgound.height = 340;
			frameContent.addChild(contentBackgound);
			
			var tButton1:TextButton = ComponentFactory.Instance.creat("BuleTextButton");
			tButton1.text = "蓝色按钮";
			tButton1.x = 20;
			tButton1.y = 20;
			frameContent.addChild(tButton1);
			
			var check:SelectedTextButton = ComponentFactory.Instance.creat("checkBox");
			check.beginChanges();
			check.text = "CheckBox0";
			check.x = 150;
			check.y = 18;
			check.selected = false;
			check.commitChanges();
			frameContent.addChild(check);
			
			var check1:SelectedTextButton = ComponentFactory.Instance.creat("checkBox");
			check1.beginChanges();
			check1.text = "GroupItem 1";
			check1.x = 180;
			check1.y = 150;
			check1.selected = false;
			check1.commitChanges();
			frameContent.addChild(check1);
			
			var check2:SelectedTextButton = ComponentFactory.Instance.creat("checkBox");
			check2.beginChanges();
			check2.text = "GroupItem 2";
			check2.x = 320;
			check2.y = 150;
			check2.selected = false;
			check2.commitChanges();
			frameContent.addChild(check2);
			
			var checkgroup:SelectedButtonGroup = new SelectedButtonGroup();
			checkgroup.addSelectItem(check1);
			checkgroup.addSelectItem(check2);
			
			
			var vscroll:VScrollbar = ComponentFactory.Instance.creat("VScrollbar");
			vscroll.height = 200;
			vscroll.x = 600;
			vscroll.y = 20;
			frameContent.addChild(vscroll);
			
			var hscroll:HScrollbar = ComponentFactory.Instance.creat("HScrollbar");
			hscroll.width = 200;
			hscroll.x = 300;
			hscroll.y = 20;
			frameContent.addChild(hscroll);
			
			
			var textInput:TextInput = ComponentFactory.Instance.creat("textinput");
			textInput.width = 200;
			textInput.height = 28;
			textInput.textField.textField.autoSize = TextFieldAutoSize.NONE;
			textInput.x = 20;
			textInput.y = 60;
			textInput.textField.text = "TextInput :Type here";
			frameContent.addChild(textInput);
			
			var listpanel:ListPanel = ComponentFactory.Instance.creat("ListPanel");
			listpanel.beginChanges();
			listpanel.horizontalScrollProxy = BaseScrollbar.HIDE_AWAYS;
			listpanel.vScrollbar.scrollStepSize = 28;
			listpanel.width = 140;
			listpanel.height = 150;
			listpanel.x = 20;
			listpanel.y = 100;
			listpanel.commitChanges();
			frameContent.addChild(listpanel);
			
			for(var i:int = 0;i<15;i++)
			{
				var listbutton:ListTextButtonAdapter = new ListTextButtonAdapter();
				listbutton.beginChanges();
				listbutton.backStyle="BuleTextButtonAsset"  ;
				listbutton.textStyle="BuleTextButtonTextStyle" ;
				listbutton.hgape=20 ;
				listbutton.offsetY=-3;
				listbutton.vgape=8;
				listbutton.text = "每天写一千行代码"
				listbutton.commitChanges();
				listpanel.addItem(listbutton);
			}
			listpanel.spacing = 3;
			
			var combox:ComboBox = ComponentFactory.Instance.creat("Combox");
			combox.selctedPropName = "text";
			combox.x = 180;
			combox.y = 100;
			
			for(var j:int = 0;j<15;j++)
			{
				var listbutton2:ListTextButtonAdapter = new ListTextButtonAdapter();
				listbutton2.beginChanges();
				listbutton2.backStyle="BuleTextButtonAsset"  ;
				listbutton2.textStyle="BuleTextButtonTextStyle" ;
				listbutton2.hgape=20 ;
				listbutton2.offsetY=-3;
				listbutton2.vgape=8;
				listbutton2.text = "每天写一千行代码";
				listbutton2.commitChanges();
				combox.list.addItem(listbutton2);
			}
			frameContent.addChild(combox);
			
			
			var tButton2:TextButton = ComponentFactory.Instance.creat("BuleTextButton");
			tButton2.text = "显示弹窗";
			tButton2.x = 520;
			tButton2.y = 300;
			tButton2.addEventListener(MouseEvent.CLICK,__onAlertButtonClick);
			frameContent.addChild(tButton2);
			
			var hsilder:HSilder = ComponentFactory.Instance.creat("HSilder");
			hsilder.maxValue = 100;
			hsilder.miniValue = 0;
			hsilder.x = 180;
			hsilder.y = 200;
			hsilder.stepValue = 5;
			frameContent.addChild(hsilder);
			
			var vsilder:VSilder = ComponentFactory.Instance.creat("VSilder");
			vsilder.x = 540;
			vsilder.y = 20;
			frameContent.addChild(vsilder);
			
//			while(frameContent.numChildren>0)
//			{
//				ObjectUtils.disposeObject(frameContent.getChildAt(0));
//			}
//			frame.dispose();
//			checkgroup.dispose();
		}
		
		private function __onAlertButtonClick(event:MouseEvent):void
		{
			var alert:BaseAlerFrame = AlertManager.Instance.simpleAlert("这个弹窗很牛B，那是veryvery牛B","大时代","确定","取消");
			alert.addEventListener(AlertEvent.RESPONSE,__onAlertResponse);
		}
		
		private function __onAlertResponse(event:AlertEvent):void
		{
			trace(event.responseCode);
		}
		
		private function init(event:Event = null):void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			initView();
		}
		
		private function initView():void
		{
			StageReferance.setup(stage);
			ComponentFactory.Instance.setup("PickglissuiStyle.xml",1);
			ComponentFactory.Instance.addEventListener(Event.COMPLETE,__onComponentinit);
			TipManager.Instance.setup(this);
			addEventListener(Event.ENTER_FRAME,__loadingTextHandler);
			var alertInfo:AlertInfo = new AlertInfo();
			alertInfo.buttonGape = 15;
			alertInfo.autoDispose = true;
			AlertManager.Instance.setup(this,alertInfo);
			addEventListener(MouseEvent.CLICK,__stageClickTrace);
		}
		
		private function __stageClickTrace(event:MouseEvent):void
		{
			trace(stage.wmodeGPU);
		}
		
		private function __loadingTextHandler(event:Event):void
		{
			trace(ComponentFactory.Instance.loader.message);
		}
	}
}
